package com.example.controller;

import com.example.common.PageResult;
import com.example.common.Result;
import com.example.pojo.dto.PetOrdersAddDto;
import com.example.pojo.dto.PetOrdersQueryDto;
import com.example.pojo.vo.PetOrdersQueryVo;
import com.example.service.PetOrdersService;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;
import java.util.List;

/**
 * 宠物订单 controller 层
 */
@RestController
@RequestMapping("/petOrders")
public class PetOrdersController {

    @Resource
    private PetOrdersService petOrdersService;

    @PostMapping("/add")
    public Result add(@RequestBody PetOrdersAddDto dto) {
        this.petOrdersService.add(dto);
        return Result.success();
    }

    @GetMapping("/pageQuery")
    public Result pageQuery(
            @RequestParam(defaultValue = "1") Integer pageNum,
            @RequestParam(defaultValue = "10") Integer pageSize,
            PetOrdersQueryDto dto
    ) {
        PageResult<PetOrdersQueryVo> pageResult = this.petOrdersService.pageQuery(pageNum, pageSize, dto);
        return Result.success(pageResult);
    }

    @GetMapping("/query")
    public Result queryById(@RequestParam Integer id) {
        PetOrdersQueryVo vo = this.petOrdersService.queryById(id);
        return Result.success(vo);
    }

    @GetMapping("/query/all")
    public Result queryAll(PetOrdersQueryDto dto) {
        List<PetOrdersQueryVo> voList = this.petOrdersService.queryAll(dto);
        return Result.success(voList);
    }

    @PutMapping("/cancel")
    public Result cancel(@RequestParam Integer id) {
        this.petOrdersService.cancel(id);
        return Result.success();
    }

    @PutMapping("/pay")
    public Result pay(@RequestParam Integer id) {
        this.petOrdersService.pay(id);
        return Result.success();
    }

    @PutMapping("/send")
    public Result send(@RequestParam Integer id) {
        this.petOrdersService.send(id);
        return Result.success();
    }

    @PutMapping("/sign")
    public Result sign(@RequestParam Integer id) {
        this.petOrdersService.sign(id);
        return Result.success();
    }
}
